package com.eascs.web.p2p.action;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.p2p.common.service.ILoaneeRefundPlanService;
import com.eascs.p2p.common.vo.LoaneeRefundPlanVO;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.AjaxButton;
import com.eascs.site.view.button.Button;
import com.eascs.tag.MenuTag;
import com.eascs.web.p2p.common.BaseMasterViewController;

@Controller
@RequestMapping("/refund")
public class LoaneeRefundPlanController extends BaseMasterViewController {

	@Reference
	ILoaneeRefundPlanService loaneeRefundPlanService;

	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "ManageRefund");
	}
	/**
	 * @Title: index
	 * @Description:还款计划列表
	 * @author 张庆奇
	 * @param vo
	 * @return
	 * @return String
	 * @throws
	 * @date 2016年7月11日 下午5:05:45
	 */
	@RequestMapping(value = "/index")
	public String index(LoaneeRefundPlanVO vo) {

		vo.setPageSize(10);
		ModelResult<PageResult<Object[]>> model =loaneeRefundPlanService.findPageLoaneeRefundPlanEntity(vo);
		PageResult<Object[]> pageResult=new PageResult<Object[]>();
		if(model.isSuccess()){
			 pageResult = model.getModel();
		} 
			
		

		String[] titles = { "项目编号","项目名称", "借款人","还款方式", "其次", "还款日", "应还金额" ," 借款人账户余额  " ,"是否逾期 "};
				
		AjaxButton planButton=new AjaxButton("还款计划                   ", "/refundRest/plan?id=");
		AjaxButton cuiButton=new AjaxButton("催款                   ", "/refundRest/warn?id=");
		AjaxButton refundButton=new AjaxButton("还款                   ", "/refundRest/refund?id=");
		
		Button[] buttons = new Button[] {planButton,cuiButton,refundButton};
		String pageUrl = "/refund/index";

		pageUrl = UrlUtil.appendUrl(pageUrl, "billCode", vo.getBillCode());
		pageUrl = UrlUtil.appendUrl(pageUrl, "title", vo.getTitle());
		pageUrl = UrlUtil.appendUrl(pageUrl, "loaneeName", vo.getLoaneeName());
		pageUrl = UrlUtil.appendUrl(pageUrl, "isOverdue", vo.getIsOverdue());
		pageUrl = UrlUtil.appendUrl(pageUrl, "showPage", "");
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setMoreButtons(buttons);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);
		ModelResult<LoaneeRefundPlanVO> recordModel=loaneeRefundPlanService.findNeedRefundMoney(vo);
		LoaneeRefundPlanVO  need=new LoaneeRefundPlanVO();
		if(recordModel.isSuccess()){
			need=recordModel.getModel();
			ViewContext.put("need", need);
		}
		
		ModelResult<LoaneeRefundPlanVO> recordModel2=loaneeRefundPlanService.findOverMoneyandLoanMoeny(vo);
		LoaneeRefundPlanVO  need2=new LoaneeRefundPlanVO();
		if(recordModel2.isSuccess()){
			need2=recordModel2.getModel();
			ViewContext.put("need2", need2);
		}
		ModelResult<Integer> bidNumModel=loaneeRefundPlanService.getNeedBidNum(vo);
		int bidNum=0;
		if(bidNumModel.isSuccess()){
			bidNum=bidNumModel.getModel();
			ViewContext.put("bidNum", bidNum);
		}
		BaseRestResult.refresh();
		return "/refund/index";
	}
	
	

	
}
